from dotenv import load_dotenv
import os
from pydantic_settings import BaseSettings

# 优先加载环境变量
load_dotenv('config.env')


class Settings(BaseSettings):
    # JWT 配置
    SECRET_KEY: str = os.getenv('SECRET_KEY')
    ALGORITHM: str = os.getenv('ALGORITHM', 'HS256')
    ACCESS_TOKEN_EXPIRE_MINUTES: int = int(os.getenv('EXPIRE', 300))

    # 服务器配置
    SERVER_HOST: str = os.getenv('SERVER_HOST', '0.0.0.0')
    SERVER_PORT: int = int(os.getenv('SERVER_PORT', 6061))

    # 动态生成 BASE_URL
    @property
    def BASE_URL(self):
        return f"http://{self.SERVER_HOST}:{self.SERVER_PORT}/"


# 单例配置实例
settings = Settings()
